#include "searchwin.h"
#include "ui_searchwin.h"
#include "mainwindow.h"
#include "dialog.h"
#include <QFile>
#include <QDebug>
#include <QMessageBox>
#include "id.h"
#include "searchper.h"
#include <vector>
#include "teacher.h"
#include "student.h"
#include "paper.h"
#include "program.h"
#include "picture.h"
#include "person.h"
#include "searchpro.h"
#include "searchpap.h"
using namespace std;
int n;
extern vector <Teacher*> tdata;
extern vector <student*> sdata;
extern vector <paper*> pdata;
extern vector <Program*> prdata;
searchwin::searchwin(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::searchwin)
{
    ui->setupUi(this);
}

searchwin::~searchwin()
{
    delete ui;
}

void searchwin::on_pushButton_clicked()
{
    unsigned int i;
    int r=0;
    QString str3=ui->lineEdit->text();
    if(str3!=""){
     for(i=0;i<tdata.size();i++){
         if(tdata[i]->ifhave(str3)){
             r=1;
             n=i;
             searchper*per=new(searchper);
             per->show();
             this->hide();
         }
     }
     for(;i<tdata.size()+sdata.size();i++){
         if(sdata[i-tdata.size()]->ifhave(str3)){
             r=1;
             n=i;
             searchper*per=new(searchper);
             per->show();
             this->hide();
         }

     }
     if(r==0)
     QMessageBox::critical(this,"错误","查无此人");
    }
}

void searchwin::on_pushButton_2_clicked()
{
    unsigned int i;
    int r=0;
    QString str4=ui->lineEdit_2->text();
    if(str4!=""){
        for(i=0;i<prdata.size();i++){
            if(prdata[i]->ifhave(str4)){
                r=1;
                n=i;
                searchpro*pro=new(searchpro);
                pro->show();
                this->hide();
            }
        }
        if(r==0)
        QMessageBox::critical(this,"错误","查无结果");
    }
}

void searchwin::on_pushButton_3_clicked()
{
    unsigned int i;
    int r=0;
    QString str5=ui->lineEdit_3->text();
    if(str5!=""){
        for(i=0;i<pdata.size();i++){
            if(pdata[i]->ifhave(str5)){
                r=1;
                n=i;
                searchpap* p =new searchpap;
                p->show();
                this->hide();
            }
        }
        if(r==0)
        QMessageBox::critical(this,"错误","查无结果");
    }
}

void searchwin::on_pushButton_4_clicked()
{
    closeEvent(0);
    Dialog*dialog=new(Dialog);
    dialog->show();
}

void searchwin::on_pushButton_5_clicked()
{
    this->close();
    picture * p = new picture;
    p->show();

}
